<%--
  Created by IntelliJ IDEA.
  User: 戴金睿
  Date: 2022/11/18
  Time: 21:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>EShopManager</title>
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">

    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/static/lib/bootstrap/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/static/stylesheets/theme.css"/>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/lib/font-awesome/css/font-awesome.css"/>
    <script src="${pageContext.request.contextPath}/static/lib/jquery-1.7.2.min.js" type="text/javascript"></script>

    <!-- Demo page code -->

    <style type="text/css">
        #line-chart {
            height: 300px;
            width: 800px;
            margin: 0px auto;
            margin-top: 1em;
        }

        .brand {
            font-family: georgia, serif;
        }

        .brand .first {
            color: #ccc;
            font-style: italic;
        }

        .brand .second {
            color: #fff;
            font-weight: bold;
        }
    </style>

    <script type="text/javascript">

        /**全选、全不选**/
        $(function () {
            $("#all_ck").change(function () {
                if ($(this).is(':checked')) {//全选
                    $("[name=ck]:checkbox").each(function () {
                        this.checked = true;
                        //$(this).attr("checked",true);
                    });
                } else {//全不选
                    $("[name=ck]:checkbox").each(function () {
                        this.checked = false;
                        //$(this).attr("checked",false);
                    });
                }

            });

        });

    </script>

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]-->
    <%--   <script src="${pageContext.request.contextPath}/static/lib/html5.js"></script>--%>
    <!-- [endif] -->

</head>
<body>


<!-- 顶部 -->
<c:import url="top.jsp"></c:import>

<!-- 左边部分 -->
<c:import url="left.jsp?parent=图书管理&child=回收站"></c:import>

<div class="content">
    <div class="header">
        <h1 class="page-title">图书管理</h1>
    </div>

    <ul class="breadcrumb">
        <li><a href="bookmanager.jsp">图书管理</a> <span class="divider">/</span></li>
        <li class="active">回收站</li>
    </ul>

    <div class="container-fluid">

        <div class="row-fluid">

            <span>共有 <b>${bookAndPageCountMap.pageCount}</b> 页记录</span>

            <div class="well">
                <div class="search-well">
                    <form class="form-inline" action="#">
                        <select name="control">
                            <option value="" selected="selected">--请选择--</option>
                            <option value="is_garbage">还原</option>
                            <option value="delete">删除</option>
                        </select>
                        <button  id="bulkBtn" type="button"><i class="icon-legal"></i> 操作</button>
                    </form>
                </div>


                <table class="table">
                    <thead>
                    <tr id="theTableTitle">
                        <th>
                            <input type="checkbox" id="all_ck"/>
                            编号
                        </th>
                        <th>书名</th>
                        <th>价格</th>
                        <th>所属分类</th>
                        <th>操作</th>
                    </tr>
                    </thead>

                    <tbody>
                    <c:forEach items="${bookAndPageCountMap.tbBookList}" var="tbBookList">

                        <tr>
                            <td>
                                <input type="checkbox" id="ck" name="ck" value="${tbBookList.bookId}"/>
                                    ${tbBookList.bookId}
                            </td>
                            <td>${tbBookList.bookName}</td>
                            <td>￥${tbBookList.bookPrice}</td>
                            <td>${tbBookList.tbType.typeName}</td>
                            <td>
                                <a href="javascript:restore(${tbBookList.bookId})" title="还原"><i class="icon-fire"></i></a>
                                <a href="javascript:deleteClick(${tbBookList.bookId})" title="删除"><i
                                        class="icon-remove"></i></a>
                            </td>
                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>

            <!-- 控制返回来的page -->
            <c:set var="page" scope="request">
                <c:if test="${param.page==null}">
                    1
                </c:if>
                <c:if test="${param.page!=null}">
                    ${param.page}
                </c:if>
            </c:set>

            <!-- 保存当前查询状态 -->
            <c:set var="searchPrefixURL" scope="request">
                ${pageContext.request.contextPath}/BookTrashController/select
            </c:set>

            <div class="pagination pagination myul">
                <%--        <ul>--%>
                <%--          <li class='disabled'><a href="#">&laquo;首页</a></li>--%>
                <%--          <li class='disabled'><a href="#">上一页</a></li>--%>
                <%--          --%>
                <%--          <li class='active'><a href="#">2</a></li>--%>
                <%--        --%>
                <%--          <li><a href="#">下一页</a></li>--%>
                <%--          <li><a href="#">尾页&raquo;</a></li>--%>
                <%--        </ul>--%>
                <ul>
                    <%--  active  disabled--%>
                    <%--是第一页--%>
                    <c:if test="${requestScope.page == 1}">
                        <li class='disabled'><a href="#">&laquo;首页</a></li>
                        <li class='disabled'><a href="#">上一页</a></li>
                    </c:if>
                    <%--不是第一页--%>
                    <c:if test="${requestScope.page != 1}">
                        <li class=''><a href="${requestScope.searchPrefixURL}?page=1">
                            首页</a></li>
                        <li class=''><a href="${requestScope.searchPrefixURL}?page=${requestScope.page-1}">
                            上一页</a></li>
                    </c:if>

                    <!-- 填充页数 -->
                    <c:forEach begin="1" end="${bookAndPageCountMap.pageCount}" varStatus="loop">
                        <%--是当前页--%>
                        <c:if test="${requestScope.page == loop.index}">
                            <li class='active'>
                                <a href="javascript:">${loop.index}</a>
                            </li>
                        </c:if>
                        <%--不是当前页--%>
                        <c:if test="${requestScope.page != loop.index}">
                            <li class=''>
                                <a href="${requestScope.searchPrefixURL}?page=${loop.index}">${loop.index}</a>
                            </li>
                        </c:if>
                    </c:forEach>

                    <!-- 最后一页 -->
                    <c:if test="${requestScope.page == bookAndPageCountMap.pageCount}">
                        <li class='disabled'>
                            <a href="#">下一页</a>
                        </li>
                        <li class='disabled'>
                            <a href="#">尾页&raquo;</a>
                        </li>
                    </c:if>

                    <!-- 不是最后一页 -->
                    <c:if test="${requestScope.page != bookAndPageCountMap.pageCount}">
                        <li>
                            <a href="${requestScope.searchPrefixURL}?page=${requestScope.page+1}">
                                下一页</a>
                        </li>
                        <li>
                            <a href="${requestScope.searchPrefixURL}?page=${bookAndPageCountMap.pageCount}">
                                尾页&raquo;</a>
                        </li>
                    </c:if>
                </ul>
            </div>


        </div>

        <!-- 底部 -->
        <c:import url="footer.jsp"></c:import>
    </div>


</div>

<script type="text/javascript" src="${pageContext.request.contextPath}/static/lib/tooltips.js"></script>
<script src="${pageContext.request.contextPath}/static/lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript">
    picUrl("${pageContext.request.contextPath}")
    // $("[rel=tooltip]").tooltip();
    // $(function () {
    //     $('.demo-cancel-click').click(function () {
    //         return false;
    //     });
    // });

    //删除
    function deleteClick(book_id) {
        //alert("==")
        if (confirm("你确定要删除该书本吗?")) {
            show_loading();
            //ajax请求servlet
            var url = " ${pageContext.request.contextPath}/BookTrashController/deleteBook/"+book_id;

            $.post(url, function (response) {
                // var jsonData=$.parseJSON(response);
                // var result=jsonData.status;
                // console.log(response)
                // console.log(response["effectRow"])
                var responseUrl = "${requestScope.searchPrefixURL}?page=${requestScope.page}";
                console.log(response)
                if (response.effectRow == 1) {
                    //跳转到responseUrl
                    show_msg('操作成功', responseUrl);
                } else {
                    show_err_msg('操作失败');
                }
            });
        }
    }

    //还原
    function restore(book_id) {
        if (confirm("你确定将该书本移出回收站吗?")) {
            show_loading();
            //ajax请求servlet
            var url = " ${pageContext.request.contextPath}/BookTrashController/updateBook/" + book_id;

            $.post(url, function (response) {
                // var jsonData=$.parseJSON(response);
                // var result=jsonData.status;
                // console.log(response)
                // console.log(response["effectRow"])
                var responseUrl = "${requestScope.searchPrefixURL}?page=${requestScope.page}";

                if (response.effectRow == 1) {
                    //跳转到responseUrl
                    show_msg('操作成功', responseUrl);
                } else {
                    show_err_msg('操作失败');
                }
            });
        }
    }

    //批量操作
    $(function() {
        // $("#bulkBtn").click(function() {
        //     return false;
        // });

        $("#bulkBtn").click(function(){
            //操作下拉框的值
            var is_garbageOrDelete=$("select[name='control']").val();
            if (is_garbageOrDelete=='') {
                show_err_msg("请选择您要的操作");
            }else{

                var ckValArray=[];
                //复选框选中的值
                $("input[name='ck']:checked").each(function(){
                    ckValArray.push($(this).val());
                });

                if (ckValArray.length==0) {
                    show_err_msg("请选择编号");
                }else{
                    show_loading();
                    <!-- 选中复选框要操作的书本id，用逗号拼接成字符串 -->
                    var bookIds=ckValArray.join(",");
                    var url="${pageContext.request.contextPath}/BookTrashController/restoreOrDelete";
                    var data={
                        is_garbageOrDelete:is_garbageOrDelete, //包含需要操作的名字
                        bookIds:bookIds     //包含书本id
                    };

                    $.post(url,data,function(response){
                        // var jsonData=$.parseJSON(response);
                        // var result=jsonData.status;
                        console.log(response);
                        var responseUrl="${requestScope.searchPrefixURL}?page=${requestScope.page}";
                        if(response.effectRow>0){
                            show_msg('操作成功',responseUrl);
                        }else{
                            show_err_msg('操作失败');
                        }
                    });
                }

            }
        });

    });
</script>

</body>
</html>